package me.helllp.book.jvm.ch02;

import java.lang.reflect.Method;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

/**
 * Java方法区产生溢出
 * VM Args：  -XX:PermSize=2M -XX:MaxPermSize=2M
 * 
 * @author linxm
 *
 */
public class JavaMethodAreaOOM {
    public static void main(String[] args) {
        while(true){
            Enhancer enchancer = new Enhancer();
            enchancer.setSuperclass(OOMObject.class);
            enchancer.setUseCache(false);
            enchancer.setCallback(new MethodInterceptor() {
                
                @Override
                public Object intercept(Object arg0, Method arg1, Object[] arg2,
                        MethodProxy arg3) throws Throwable {
                    return arg3.invokeSuper(arg0, arg2);
                }
            });
        }
    }
    
    class OOMObject{
        
    }
}